#pragma once

#include <windows.h>
#include <vector>

namespace Xiol
{

/*
	ControllerEnumerationTrigger

	Base class for the object that can be used to trigger a controller enumeration 
	(ie an update of the Controller List) at the ControllerManager level.
*/
class ControllerEnumerationTrigger
{
public:
	virtual~ ControllerEnumerationTrigger() {}
	virtual bool	enumerationNeeded() = 0;
};

/*
	WindowsHookEnumerationTrigger

	A trigger based on a Windows Proc hook. The hook is installed, then
	whenever a WM_DEVICECHANGE message is received, the trigger indicates 
	that a device enumeration at the ControllerManager level is needed
*/
class WindowsHookEnumerationTrigger : public ControllerEnumerationTrigger
{
public:
	WindowsHookEnumerationTrigger();	
	virtual ~WindowsHookEnumerationTrigger();
	virtual bool	enumerationNeeded();

private:
	static LRESULT CALLBACK wndProcHook( int nCode, WPARAM wParam, LPARAM lParam );
	static std::vector<WindowsHookEnumerationTrigger*> mTriggerInstances;
	static HHOOK	mHookHandle;
	bool			mEnumerationNeeded;
};	
	
/*
	TimeBasedEnumerationTrigger
*/
class TimeBasedEnumerationTrigger : public ControllerEnumerationTrigger
{
public:
	TimeBasedEnumerationTrigger( unsigned int intervalInMs );	
	virtual bool	enumerationNeeded();

private:
	int				updateNextTime();

	unsigned int	mIntervalInMs;
	unsigned int	mStartTime;
	unsigned int	mNextTime;
};	

}